﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chapter23
{
    using System.Reflection;
    //using Chapter23.View;
    //using Chapter23.ViewModel;

    /// <summary>
    /// 第23章 数据视图
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            #region 01 Window 类
            /*
             * 01 显示窗口
             * 02 定位窗口
             * 03 保存和还原窗口位置
             * */
            #endregion

            #region 02 窗口交互
            /*
             * 01 窗口所有权
             * 02 对话框模型
             * 03 通用对话框
             * */
            #endregion

            #region 03 非矩形窗口
            /*
             * 01 简单形状窗口
             * 02 具有形状内容的透明窗口
             * 03 移动形状窗口
             * 04 改变形状窗口的尺寸
             * 05 组合到一起：窗口的自定义控件模板
             * */
            #endregion

            #region 04 小结
            #endregion
        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Open)
            {
                var button = e.Source as Button;
                var assembly = Assembly.GetExecutingAssembly();
                var name = "Chapter23.View." + button.Tag;
                var type = assembly.GetType(name);
                Demo(Activator.CreateInstance(type, true) as Window);
            }
        }

        private void Demo(Window window)
        {
            window.Owner = this;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.ShowDialog();
        }
    }
}
